/**
 * Created by Administrator on 2017/4/5 0005.
 */
var PageMask1={
    create:function () {
        var page={};
        page.ui=new PIXI.DisplayObjectContainer();

        // var sp_mask=new PIXI.Sprite();
        // var sp_content=Easy.CreateSprite('assets/images/pt1_bg.png',0,0,0,0,1);
        // sp_content.mask=sp_mask;

        var sp_bg=Easy.CreateSprite('assets/images/pt2_bg.png',0,0,0,0,0);
        sp_bg.x=0;
        sp_bg.y=0;
        // page.ui.addChild(sp_bg);

        var con_blur=new PIXI.DisplayObjectContainer();
        var arr_piece=[];
        page.ui.addChild(con_blur);
        con_blur.pivot.x=740/2;
        con_blur.pivot.y=1136/2;
        con_blur.x=740/2;
        con_blur.y=1136/2;
        con_blur.interactive=false;
        con_blur.on('pointerdown',downHandler);
        for(var i=0;i<300;i++)
        {
            var texture=resource["assets/images/pt2_bg.png"].texture.clone();
            var square=new PIXI.Rectangle(0,1136/300*i,740,1136/300);
            texture.frame=square;
            var piece=new PIXI.Sprite(texture);
            piece.x=0;
            piece.y=1136/300*i;
            arr_piece.push(piece);
            con_blur.addChild(piece);

            // var texture=resource["assets/images/pt1_bgBlur.png"].texture.clone();
            // var square=new PIXI.Rectangle(0,1136/300*i,740,1136/300);
            // texture.frame=square;
            // var piece=new PIXI.Sprite(texture);
            // piece.x=0;
            // piece.y=0+1136/300*i;
            // arr_piece.push(piece);
            // con_blur.addChild(piece);
        }

        var sp_text0=Easy.CreateSprite('assets/images/mask0_t0.png',370,567,0.5,0.5,0);
        page.ui.addChild(sp_text0);

        var sp_text1=Easy.CreateSprite('assets/images/mask1_t3.png',370,165,0.5,0.5,0);
        page.ui.addChild(sp_text1);

        var loading=Easy.CreateSprite('assets/images/loading.png',120,55,0.5,0.5,0);
        page.ui.addChild(loading);
        TweenMax.to(loading,1,{alpha:1,repeat:-1,yoyo:true,repeatDelay:0.5,ease:Linear.easeNone});

        page.In=function () {
            // sp_content.alpha=0
            // TweenMax.to(sp_bg,1,{delay:2.5,alpha:1});
            TweenMax.to(con_blur.scale,2,{repeat:-1,yoyo:true,x:1.03,y:1.03,ease:Cubic.easeInOut});
            for(var i=0;i<arr_piece.length;i++)
            {
                if(i%2==0)
                {
                    arr_piece[i].x = -740;
                }
                else
                {
                    arr_piece[i].x = 740;
                }
                arr_piece[i].alpha=1;
                TweenMax.to(arr_piece[i],0.5,{delay:i*0.005,alpha:1,x:0,ease:Cubic.easeInOut});
                arr_piece[i].scale.x=arr_piece[i].scale.y=1;
            }

            // TweenMax.to(sp_bgBlur,1,{delay:2,alpha:1,ease:Cubic.easeInOut});

            sp_text0.alpha=0;
            sp_text0.y=280+25;
            TweenMax.to(sp_text0,1,{delay:3.5,alpha:1,y:280,ease:Back.easeOut,onComplete:function () {
                con_blur.interactive=true;

            }});

            sp_text1.y=170+25;
            TweenMax.to(sp_text1,1,{delay:3,alpha:1,y:170,ease:Back.easeOut});
        }

        var bool_down;
        function downHandler(e)
        {
            // sp_bgBlur.interactive=false;

            if(!bool_down)
            {
                bool_down=true;
                TweenMax.to(sp_text0,1,{alpha:0,y:sp_text0.y-100,ease:Back.easeIn});
                TweenMax.to(sp_text1,1,{alpha:0,y:sp_text1.y-100,ease:Back.easeIn});
                setTimeout(function () {
                    con_blur.interactive=false;
                    TweenMax.to(con_blur,3,{delay:0,alpha:0,ease:Linear.easeNone,onComplete:function () {

                        // contentIn();
                    }});
                },1500)
                setTimeout(function () {
                    // document.dispatchEvent(new CustomEvent('Game_PageIn',{'detail':'pageTouch0'}));
                    document.dispatchEvent(new CustomEvent('Game_PageIn',{'detail':'mask2'}));
                },2000);
            }
            if(ripples.length<5)
            {
                var ripple=new Ripple(e.data.global.x/(innerWidth/pixiStageW), e.data.global.y/(innerHeight/pixiStageH),page.ui);
                ripples.push(ripple);

                con_blur.filters = ripples.map(function (element) {
                    return element.filter;
                });
            }

        }
        function contentIn() {
            sp_text1.y=200+100;
            TweenMax.to(sp_text1,1,{alpha:1,y:200,ease:Back.easeOut});

            setTimeout(function () {
                // document.dispatchEvent(new CustomEvent('Game_PageIn',{'detail':'pageTouch0'}));
                document.dispatchEvent(new CustomEvent('Game_PageIn',{'detail':'mask2'}));
            },3500);
        }

        return page;
    }
}